package test;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Writer;

//显示服务器给浏览器写回cookie
public class ServletDemo7 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Cookie name = new Cookie("name","yanxin");
        Cookie age = new Cookie("age","21");
        //把cookie写回响应
       resp.addCookie(name);
       resp.addCookie(age);
       //创建一个响应报文
        resp.setContentType("text/html;charset=utf-8");
        resp.getWriter().write("返回响应成功");

    }
}
